<navigation:Page 
    x:Class="ibba.src.noriskbo.views.PageLancamentoManual" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:slc="clr-namespace:ibba.src.sl.componentes;assembly=ibba.src.sl.componentes"
    xmlns:vm="clr-namespace:ibba.src.noriskbo.ViewModels"
    xmlns:local="clr-namespace:ibba.src.noriskbo"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    mc:Ignorable="d"
    Title="LancamentoManual Page"
    d:DesignHeight="300" d:DesignWidth="800">

    <navigation:Page.Resources>
        <vm:PageLancamentoManualViewModel x:Key="viewModel"/>
        <sys:Double x:Key="colDetailLabel1">80</sys:Double>
        <sys:Double x:Key="colDetailValue1">150</sys:Double>
        <sys:Double x:Key="colDetailLabel2">95</sys:Double>
        <sys:Double x:Key="colDetailValue2">165</sys:Double>
        <sys:Double x:Key="colDetailLabel3">110</sys:Double>        
    </navigation:Page.Resources>

    <Grid x:Name="LayoutRoot" Background="White" Margin="10,5,10,15" DataContext="{Binding Source={StaticResource viewModel}}" >
        <toolkit:BusyIndicator IsBusy="{Binding IsBusy}" BusyContent="{Binding BusyText}">
            <Grid>
                <Grid x:Name="gridHome" VerticalAlignment="Top" Visibility="{Binding ElementName=gridContent, Path=Visibility, Converter={StaticResource NotVisibilityConverter}}">
                    <TextBlock Name="lblTituloPagina" Text="{Binding TitleView}" Style="{StaticResource TitlePage}" />
                    <local:PainelStatusLM x:Name="painelConsultaStatusLM" Margin="20,90,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"/>
                </Grid>

                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Grid x:Name="gridContent" Grid.RowSpan="2"
                          Visibility="{Binding StateView, Converter={StaticResource BooleanToVisibilityConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition />
                        </Grid.RowDefinitions>

                        <Grid x:Name="gridResultBusca" Grid.Row="0" Margin="0,5" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="3,0">
                                <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
                                    <TextBlock Text="Conteúdo pesquisado:" VerticalAlignment="Center" Style="{StaticResource SubTitleHeader}" />                                    
                                    <TextBlock x:Name="lblCriterioPesquisa" VerticalAlignment="Center" FontSize="12" Margin="5,0" />
                                </StackPanel>
                                <TextBlock x:Name="lblRegLocalizado" Text="Localizado" VerticalAlignment="Center" Style="{StaticResource SubTitleHeader}" FontSize="10" />
                            </StackPanel>

                            <slc:CustomButtonBar Name="btnHome" Image="{StaticResource IconeHome}"
                                             VerticalAlignment="Top" Grid.Column="1" ImageSizeNormal="20" ImageSizeOver="24" 
                                             Content="" Click="btnHome_Click"/>
                        </Grid>

                        <Grid x:Name="gridDados" Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <local:PainelListaContratos x:Name="painelListaContratos" DataContext="{Binding Source={StaticResource viewModel} }" />

                            <Border x:Name="bordaDetalhe" Margin="25,0,0,0" Grid.Column="1"
                                    Background="White" BorderThickness="1" BorderBrush="{StaticResource BlueOpaco}" CornerRadius="20,0,0,20">
                                <!--#FFB5B6B5-->
                                <Grid>
                                    <Border Margin="-15,10,5,5" Padding="0,8,0,8" VerticalAlignment="Top" HorizontalAlignment="Left" Background="#FFFFFFFF" >
                                        <Image Width="30" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Source="{StaticResource IconeContrato}" />
                                    </Border>

                                    <ScrollViewer x:Name="scrollDetalhe" BorderThickness="0">
                                        <toolkit:BusyIndicator IsBusy="{Binding IsBusyDetalhe}" BusyContent="Carregando detalhes...">
                                            <Grid Margin="20,10,5,5">
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="Auto"/>
                                                    <RowDefinition/>
                                                </Grid.RowDefinitions>

                                                <StackPanel Orientation="Vertical">
                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="0,2">
                                                        <TextBox Text="{Binding Operacao.CodigoContrato}" 
                                                                 FontSize="20" Foreground="#FF6B696B" BorderThickness="0" 
                                                                 IsReadOnly="True" Style="{StaticResource TextReadOnly}"/>
                                                    </StackPanel>

                                                    <Grid VerticalAlignment="Top" Margin="0,8">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition/>
                                                            <ColumnDefinition Width="Auto"/>
                                                        </Grid.ColumnDefinitions>

                                                        <StackPanel Orientation="Vertical" Grid.Column="0">
                                                            <TextBlock Text="Detalhe da Operacao" Style="{StaticResource SubTitleHeader}" />
                                                            <Border Style="{StaticResource LineGold}" HorizontalAlignment="Left" />
                                                        </StackPanel>

                                                        <slc:CustomButtonBar Name="btnDetalheOperacao" Padding="5,5" Margin="0,-55,0,0"  Grid.Column="1"
                                                                             Image="{StaticResource BotaoFormularioDetalhes}"
                                                                             ImageSizeNormal="42" ImageSizeOver="55" 
                                                                             Content="Ver detalhes" Click="btnDetalheOperacao_Click" />
                                                        
                                                        <!--<Button x:Name="btnDetalheOperacao" Click="btnDetalheOperacao_Click" Padding="5,5" Grid.Column="1">
                                                            <StackPanel Orientation="Horizontal">
                                                                <Image x:Name="imgBtnDetalheOperacao" Source="{StaticResource IconeVerDetalhes}" Height="16" Width="16" />
                                                                <TextBlock Text="ver detalhes" Margin="3,0,0,0" />
                                                            </StackPanel>
                                                        </Button>-->
                                                    </Grid>

                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="Grupo:" VerticalAlignment="Center" FontSize="13" Width="80" Foreground="#FF2B2B2B"/>
                                                        <TextBlock VerticalAlignment="Center" FontSize="13" Foreground="#FF1F3C65">
                                                            <Run Text="{Binding Operacao.IdGrupo}" />
                                                            <Run Text=" - " />
                                                            <Run Text="{Binding Operacao.NomeGrupo}" />
                                                        </TextBlock>                                                        
                                                    </StackPanel>

                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="Cliente:" VerticalAlignment="Center" FontSize="13" Width="80" Foreground="#FF2B2B2B" />
                                                        <TextBlock VerticalAlignment="Center" FontSize="13" Foreground="#FF1F3C65">
                                                            <Run Text="{Binding Operacao.IdCliente}" />
                                                            <Run Text=" - " />
                                                            <Run Text="{Binding Operacao.NomeCliente}" />
                                                        </TextBlock>
                                                    </StackPanel>
                                                    
                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="Abertura:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel1}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.DataAbertura, Converter={StaticResource DateTimeConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue1}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Vencimento:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel2}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.DataVencimento, Converter={StaticResource DateTimeConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue2}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Produto:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel3}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.CodigoProduto}" VerticalAlignment="Center" FontSize="13" Foreground="#FF1F3C65"  />
                                                    </StackPanel>

                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="Operação:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel1}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.ValorOperacaoBRL, Converter={StaticResource DecimalConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue1}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Contábil:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel2}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.ValorContabilBRL, Converter={StaticResource DecimalConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue2}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Modalidade:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel3}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.CodigoModalidade}" VerticalAlignment="Center" FontSize="13" Foreground="#FF1F3C65"  />
                                                    </StackPanel>

                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="RCP:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel1}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.ValorRcp, Converter={StaticResource DecimalConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue1}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Risco:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel2}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.ValorRiscoComprometido, Converter={StaticResource DecimalConverter}}" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailValue2}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Rating:" VerticalAlignment="Center" FontSize="13" Width="{StaticResource colDetailLabel3}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.RiskRating}" VerticalAlignment="Center" FontSize="13" Foreground="#FF1F3C65"  />
                                                    </StackPanel>

                                                    <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="5,1">
                                                        <TextBlock Text="Origem:" VerticalAlignment="Top" FontSize="13" Width="{StaticResource colDetailLabel1}" Foreground="#FF2B2B2B" />
                                                        <TextBlock Text="{Binding Operacao.DescricaoOrigem}" VerticalAlignment="Top" FontSize="13" Width="{StaticResource colDetailValue1}" Foreground="#FF1F3C65" />

                                                        <TextBlock Text="Status:" VerticalAlignment="Top" FontSize="13" Width="{StaticResource colDetailLabel2}" Foreground="#FF2B2B2B" />                                                        
                                                        <Image Source="{Binding Operacao.CodigoStatus, Converter={StaticResource StatusImageConverter}, ConverterParameter='mini'}" 
                                                               Width="16" Height="16" VerticalAlignment="Top" Margin="-4,0,0,0"/>
                                                        <TextBlock Text="{Binding Operacao.Status}" VerticalAlignment="Top" FontSize="13" Width="148" Foreground="#FF1F3C65" TextWrapping="Wrap" />

                                                        <TextBlock Text="Tipo Sublimite:" VerticalAlignment="Top" FontSize="13" Width="{StaticResource colDetailLabel3}" Margin="7, 0" Foreground="#FF2B2B2B" />
                                                        <TextBlock VerticalAlignment="Top" FontSize="13" Foreground="#FF1F3C65" Margin="-6, 0">
                                                            <Run Text="{Binding Operacao.IdAreaSubLimite}" />
                                                            <Run Text=" - " />
                                                            <Run Text="{Binding Operacao.DescAreaSubLimite}" />
                                                            <Run Text="{Binding Operacao.DescAreaLimite, StringFormat=' (\{0\})'}" FontSize="10" Foreground="Gray" />
                                                        </TextBlock>
                                                    </StackPanel>

                                                </StackPanel>

                                                <Border Background="#FFEFEFEF" Grid.Row="1" Margin="0,5,15,25" Padding="7">
                                                    <Grid Background="White">
                                                        <StackPanel Orientation="Vertical" VerticalAlignment="Top" Margin="3">
                                                            <TextBlock Text="Garantias da Operação" Style="{StaticResource SubTitleHeader}" />
                                                            <Border Style="{StaticResource LineGold}" HorizontalAlignment="Left" />
                                                        </StackPanel>

                                                        <sdk:DataGrid Name="dataGridGarantias" ItemsSource="{Binding Garantias}"
                                                                      AutoGenerateColumns="False" GridLinesVisibility="All" VerticalScrollBarVisibility="Auto" 
                                                                      Margin="0,30,0,0" IsReadOnly="True" MinHeight="120" >
                                                            <sdk:DataGrid.Columns>
                                                                <sdk:DataGridTemplateColumn>
                                                                    <sdk:DataGridTemplateColumn.CellTemplate>
                                                                        <DataTemplate>
                                                                            <Button Name="btnDetalheGarantia" Click="btnDetalheGarantia_Click">
                                                                                <Image Source="{StaticResource IconeVerDetalhes}" Width="16" Height="16" />
                                                                            </Button>
                                                                        </DataTemplate>
                                                                    </sdk:DataGridTemplateColumn.CellTemplate>
                                                                </sdk:DataGridTemplateColumn>
                                                                <sdk:DataGridTextColumn Header="Numero" Binding="{Binding Numero}" MinWidth="75" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Instrumento" Binding="{Binding DescricaoInstrumento}" MinWidth="120" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Bem" Binding="{Binding DescricaoBem}" MinWidth="120" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Natureza" Binding="{Binding DescricaoNatureza}" MinWidth="120" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Moeda" Binding="{Binding Moeda}" MinWidth="50" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Valor atualizado" Binding="{Binding ValorAtualizado, Converter={StaticResource DecimalConverter}}" MinWidth="120" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Origem" Binding="{Binding DescricaoOrigem}" MinWidth="60" Width="Auto" />
                                                                <sdk:DataGridTextColumn Header="Status" Binding="{Binding DescricaoStatus}" MinWidth="90" Width="Auto" />
                                                            </sdk:DataGrid.Columns>

                                                        </sdk:DataGrid>
                                                    </Grid>
                                                </Border>
                                            </Grid>

                                        </toolkit:BusyIndicator>
                                    </ScrollViewer>

                                </Grid>
                            </Border>
                        </Grid>
                    </Grid>

                    <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Right" Margin="0,0,30,5" Background="White">
                        <TextBlock Text="Quantidade de garantias associadas a contratos inexistentes:" FontSize="12" VerticalAlignment="Center"/>
                        <HyperlinkButton x:Name="lnkGarantiasSemContratos" Content="{Binding GarantiasSemContrato.Count, FallbackValue=0}"
                                         VerticalAlignment="Center" Margin="5,0" Foreground="Blue"
                                         Click="lnkGarantiasSemContratos_Click" FontSize="14" />
                        <TextBlock Text="(clique no número para visualizar)" VerticalAlignment="Center" FontSize="10"/>
                    </StackPanel>
                </Grid>
            </Grid>
        </toolkit:BusyIndicator>
    </Grid>
</navigation:Page>